<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./jquery-1.12.4.min.js"></script>
    <script src="./echarts.common.min.js"></script>

</head>

<body>
    <!-- 为ECharts准备一个具备大小（宽高）的Dom -->
    <div id="main" style="width: 600px;height:400px;"></div>

    <script>
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('main'));
        // 指定图表的配置项和数据

        tempData = [];
        timeData = [];
        count = 1
        var option = {
            title: {
                text: 'ECharts 入门示例'
            },
            tooltip: {},
            legend: {
                data: ['温度']
            },
            xAxis: {
                data: []
            },
            yAxis: {},
            series: [{
                name: '温度',
                type: 'bar',
                data: []
            }]
        };
        $(function () {
            setInterval(function () {
                //从GetTemp.do中获取温度信息
                $.ajax({
                    type: "GET",
                    url: "http://10.1.93.241:8082/GetTemp.do",
                    success: function (res) {
                        //res 中包含着温度信息
                        var obj = JSON.parse(res)
                        var temp = obj["Temp"];
                        tempData.push(temp);
                        console.log(temp)
                        //时间
                        timeData.push((count++) + "");
                        

                            option.series[0].data = tempData;
                            option.xAxis.data = timeData;
                            // 使用刚指定的配置项和数据显示图表。
                            myChart.setOption(option);
                        
                    }
                });
            }, 1000);
        });
    </script>
</body>

</html>